/*
* @Author: Administrator
* @Date:   2018-09-08 18:22:46
* @Last Modified by:   Administrator
* @Last Modified time: 2018-09-15 09:43:59
*/

import * as constants from './constants.js';
import axios from 'axios';
import { fromJS } from 'immutable'

const changeList = (data) => {
	return {
		type: constants.CHANGE_LIST,
		//从接口传过来的数据是一个js数组因为在reducer中是immutable数据所以在这里将他变为immutable数组
		data: fromJS(data),
		totalPage: Math.ceil(data.length/10)
	} 
}



export const getFocuse = () => ({
	type: constants.GET_FOCUSE
});
export const loseFocuse = () => ({
	type: constants.LOSE_FOCUSE
});
export const changePage = (page) => ({
	type: constants.CHANGE_PAGE,
	page
});
export const mouseEnter = () => ({
	type: constants.MOUSE_ENTER
});
export const mouseLeave = () => ({
	type: constants.MOUSE_LEAVE
});

export const getList = () => {
	return (dispatch) => {
		 axios.get('/api/headerList.json').then((res) => {
		   const data = res.data;
       dispatch(changeList(data.data));
    }).catch(() => {
    	console.log('请求失败');
    })
	}
}